<template>

  <el-dialog title="用户分类" v-model="dialogVisible" @close='dialogFormVisible' :close-on-click-modal="false"
    :close-on-press-escape="false" width="600px">

      		<el-form size="small" :model="form" :rules="formRules" ref="form">

			<el-form-item label="分类名称" prop="name" :label-width="formLabelWidth">
				<!-- <el-input v-model="form.name" autocomplete="off"></el-input> -->
             <el-radio-group v-model="form.user_category">
                <el-radio value=1 size="small">个人买家</el-radio>
                <el-radio value=2 size="small">餐饮</el-radio>
                <el-radio value=3 size="small">商超</el-radio>
              </el-radio-group>
			</el-form-item>

		</el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="dialogFormVisible">取 消</el-button>
        <el-button type="primary" @click="submit_user_category()" :loading="loading">确 定</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script>
  import {userCategory} from '@/api/user.js';
  export default {
    data() {
      return {
        loading: false,
        /*左边长度*/
        formLabelWidth: '120px',
        /*是否显示*/
        dialogVisible: false,
        /*默认选中*/
        activeName: 0,
        source: 0,
      };
    },
    props: ['open_user_category', 'form'],
    created() {
      this.dialogVisible = this.open_user_category;
      // console.log(this.form);
    },
    methods: {
      submit_user_category() {
          // console.log(this.form);
          self.loading = true;
          var data = {user_id:this.form.user_id,user_category:this.form.user_category};
          ElMessageBox.confirm("确定更改用户分类吗？", "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "info",
				  }).then(() => {
              self.loading = true;
              userCategory(data).then((res) => {
                  self.loading = false;
                  ElMessage({
                    message: '修改成功',
                    type: 'success',
                  });
                  self.dialogFormVisible(true);
              }).catch((error) => {
                  self.loading = false;
              });
					}).catch((error) => {
						  self.loading = false;
					});

      },

      /*关闭弹窗*/
      dialogFormVisible(e) {
        if (e) {
          this.$emit('closeDialog', {
            type: 'success',
            openDialog: false
          })
        } else {
          this.$emit('closeDialog', {
            type: 'error',
            openDialog: false
          })
        }
      }

    }
  };
</script>

<style></style>
